namespace ZeroSum.Models;

/// <summary>
///     分页泛型集合
/// </summary>
/// <typeparam name="TEntity"></typeparam>
public sealed class PagedResponseModel<TEntity> where TEntity : new()
{
    public PagedResponseModel(int pageNumber, int pageSize, int totalCount, IReadOnlyList<TEntity> items)
    {
        PageNumber = pageNumber;
        PageSize = pageSize;
        TotalCount = totalCount;
        Items = items;
    }

    /// <summary>
    ///     页码
    /// </summary>
    public int PageNumber { get; }

    /// <summary>
    ///     页容量
    /// </summary>
    public int PageSize { get; }

    /// <summary>
    ///     总条数
    /// </summary>
    public int TotalCount { get; }

    /// <summary>
    ///     总页数
    /// </summary>
    public int TotalPages => TotalCount / PageSize + (TotalCount % PageSize == 0 ? 0 : 1);

    /// <summary>
    ///     当前页集合
    /// </summary>
    public IReadOnlyList<TEntity>? Items { get; }

    /// <summary>
    ///     是否有上一页
    /// </summary>
    public bool HasPrevPages => PageNumber > 1;

    /// <summary>
    ///     是否有下一页
    /// </summary>
    public bool HasNextPages => PageNumber < TotalPages;
}